package com.hdjk.view.callback;

import com.hdjk.view.entity.WalletProfitEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class GetWalletProfitListCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONObject object = (JSONObject) msg.getData();
        if (object!=null) {
            List<WalletProfitEntity> list=new ArrayList<>();
            if (!object.isNull("data")){
                JSONArray array=object.getJSONArray("data");
                if (array!=null){
                    for (int j=0;j<array.length();j++){
                        WalletProfitEntity entity=new WalletProfitEntity();
                        JSONObject jsonObject=array.getJSONObject(j);
                        if (!jsonObject.isNull("dailyProfit")){
                            entity.setDailyProfit(jsonObject.getString("dailyProfit"));
                        }
                        if (!jsonObject.isNull("date")){
                            entity.setDate(jsonObject.getString("date"));
                        }
                        if (!jsonObject.isNull("profits")){
                            entity.setProfits(jsonObject.getString("profits"));
                        }
                        list.add(entity);
                    }
                }
            }
            msg.setData(list);
        }
        return msg;
    }
}
